﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.FactoryManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.FactoryManagement.ProductionLineVMs
{
    public partial class ProductionLineListVM : BasePagedListVM<ProductionLine_View, ProductionLineSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProductionLine_View>> InitGridHeader()
        {
            return new List<GridColumn<ProductionLine_View>>{
                
                this.MakeGridHeader(x => x.ProductionLine_Name).SetTitle(@Localizer["Page.产线名称"].Value),
                this.MakeGridHeader(x => x.ProductionLine_Code).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.ProductionLine_Product).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.ProductionLine_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.ProductionLine_PrincipalId).SetTitle(@Localizer["Page.负责人"].Value),
                this.MakeGridHeader(x => x.ProductionLine_Active).SetTitle(@Localizer["Page.激活"].Value),
                this.MakeGridHeader(x => x.ProductionLine_Aux_1).SetTitle(@Localizer["Page.备用1"].Value),
                this.MakeGridHeader(x => x.ProductionLine_Aux_2).SetTitle(@Localizer["Page.备用2"].Value),
                this.MakeGridHeader(x => x.ProductionLine_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProductionLine_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProductionLine_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProductionLine_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ProductionLine_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProductionLine_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionLine>()
                
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                //.CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckEqual(Searcher.PrincipalIdId, x=>x.PrincipalIdId)
                .CheckEqual(Searcher.Active, x=>x.Active)
                .CheckContain(Searcher.Aux_1, x=>x.Aux_1)
                .CheckContain(Searcher.Aux_2, x=>x.Aux_2)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProductionLine_View
                {
				    ID = x.ID,
                    
                    ProductionLine_Name = x.Name,
                    ProductionLine_Code = x.Code,
                 
                    ProductionLine_PrincipalId = DC.Set<FrameworkUser>().Where(z0 => z0.ITCode == x.PrincipalIdId).Select(y => y.Name).FirstOrDefault(),
                    ProductionLine_Active = x.Active,
                    ProductionLine_Aux_1 = x.Aux_1,
                    ProductionLine_Aux_2 = x.Aux_2,
                    ProductionLine_CreateTime = x.CreateTime,
                    ProductionLine_UpdateTime = x.UpdateTime,
                    ProductionLine_CreateBy = x.CreateBy,
                    ProductionLine_UpdateBy = x.UpdateBy,
                    ProductionLine_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProductionLine_View: ProductionLine
    {
        
        public string ProductionLine_Name { get; set; }
        public string ProductionLine_Code { get; set; }
        public string ProductionLine_Product { get; set; }
        public string ProductionLine_ProductName { get; set; }
        public string ProductionLine_PrincipalId { get; set; }
        public bool? ProductionLine_Active { get; set; }
        public string ProductionLine_Aux_1 { get; set; }
        public string ProductionLine_Aux_2 { get; set; }
        public DateTime? ProductionLine_CreateTime { get; set; }
        public DateTime? ProductionLine_UpdateTime { get; set; }
        public string ProductionLine_CreateBy { get; set; }
        public string ProductionLine_UpdateBy { get; set; }
        public bool ProductionLine_IsValid { get; set; }

    }

}